package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.ResReviewImg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ResReviewMapper;
import com.ruoyi.system.domain.ResReview;
import com.ruoyi.system.service.IResReviewService;

/**
 * 餐馆评论Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-06-01
 */
@Service
public class ResReviewServiceImpl implements IResReviewService 
{
    @Autowired
    private ResReviewMapper resReviewMapper;

    /**
     * 查询餐馆评论
     * 
     * @param reviewId 餐馆评论主键
     * @return 餐馆评论
     */
    @Override
    public ResReview selectResReviewByReviewId(Long reviewId)
    {
        return resReviewMapper.selectResReviewByReviewId(reviewId);
    }

    /**
     * 查询餐馆评论列表
     * 
     * @param resReview 餐馆评论
     * @return 餐馆评论
     */
    @Override
    public List<ResReview> selectResReviewList(ResReview resReview)
    {
        return resReviewMapper.selectResReviewList(resReview);
    }

    @Override
    public List<ResReview> selectResReviewListByUserId(ResReview resReview, Long userId) {
        return resReviewMapper.selectResReviewListByUserId(resReview, userId);
    }

    /**
     * 新增餐馆评论
     * 
     * @param resReview 餐馆评论
     * @return 结果
     */
    @Override
    public int insertResReview(ResReview resReview)
    {
        // 插入评价，获取自增ID
        resReviewMapper.insertResReview(resReview);

        // 如果有图片，插入图片记录
        if (resReview.getImgList() != null && !resReview.getImgList().isEmpty()) {
            // 为每个图片设置reviewId
            for (ResReviewImg img : resReview.getImgList()) {
                img.setReviewId(resReview.getReviewId());
            }
            // 批量插入图片
            resReviewMapper.insertResReviewImgs(resReview.getImgList());
        }
        return 1;
    }

    /**
     * 修改餐馆评论
     * 
     * @param resReview 餐馆评论
     * @return 结果
     */
    @Override
    public int updateResReview(ResReview resReview)
    {
        return resReviewMapper.updateResReview(resReview);
    }

    /**
     * 批量删除餐馆评论
     * 
     * @param reviewIds 需要删除的餐馆评论主键
     * @return 结果
     */
    @Override
    public int deleteResReviewByReviewIds(Long[] reviewIds)
    {
        return resReviewMapper.deleteResReviewByReviewIds(reviewIds);
    }

    /**
     * 删除餐馆评论信息
     * 
     * @param reviewId 餐馆评论主键
     * @return 结果
     */
    @Override
    public int deleteResReviewByReviewId(Long reviewId)
    {
        return resReviewMapper.deleteResReviewByReviewId(reviewId);
    }
}
